package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class DeptServiceImpl implements DeptService {

    private final DeptMapper deptMapper;

    @Override
    public List<Dept> queryAllDepts() {

        List<Dept> depts = deptMapper.queryAllDepts();

        return depts;
    }

    @Override
    public void addDept(Dept dept) {
//        Dept dept = new Dept(null, name, LocalDateTime.now(), LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.addDept(dept);
    }

    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);

    }

    @Override
    public Dept queryDeptById(Integer id) {
        Dept dept = deptMapper.queryDeptById(id);

        return dept;
    }

    @Override
    public void deleteDeptById(Integer id) {
        deptMapper.deleteDeptById(id);
    }
}
